package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 调用有参方法
 */
public class ReflectDemo5 {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        Person p = new Person();
        p.say("大家好!");

        Class cls = Class.forName("reflect.Person");
        Object o = cls.newInstance();//new Person();
        // public void say(String info)
        Method m = cls.getMethod("say",String.class);
        m.invoke(o,"才是真的好~");


        // public void say(String info,int sum)
        // Method getMethod(String name,Class... args)
        Method m1 = cls.getMethod("say",String.class,int.class);
        m1.invoke(o,"哈哈~",5);

    }
}
